package com.shijunhao.graduation.controller.system;

import com.shijunhao.graduation.annotations.OperationLog;
import com.shijunhao.graduation.domain.bean.ResultCode;
import com.shijunhao.graduation.domain.entity.SystemFileInfo;
import com.shijunhao.graduation.properties.OperationTarget;
import com.shijunhao.graduation.properties.OperationType;
import com.shijunhao.graduation.service.system.ISystemFileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: shijunhao
 * @date: 2022/3/8 22:41
 * @description:
 */
@RestController
@RequestMapping("/file")
@Api(tags = "文件上传下载")
public class FileUpdateController {

    private final ISystemFileInfoService fileInfoService;

    @Autowired
    public FileUpdateController(ISystemFileInfoService fileInfoService) {
        this.fileInfoService = fileInfoService;
    }

    @PostMapping("/upload")
    @OperationLog(target = OperationTarget.SYSTEM,type = OperationType.UPDATE,description = "文件上传")
    @ApiOperation("文件上传")
    public ResultCode<SystemFileInfo> fileUpload(@RequestPart MultipartFile file){
        SystemFileInfo fileInfo = fileInfoService.upload(file);
        return ResultCode.success(fileInfo);
    }


    @GetMapping("/download/{fileId}")
    @ApiOperation("文件下载")
    public void download(@PathVariable Long fileId){
        fileInfoService.download(fileId);
    }
}
